package test.练习1;

import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Servers {
    public static void main(String[] args) throws Exception
    {
        //创建一个ServerSocket对象，构造方法中绑定端口号
        ServerSocket serverSocket = new ServerSocket(10086);

        //使用ServerSocket对象中的方法accept，获取到请求的客户端对象Socket
        Socket socket = serverSocket.accept();

        InputStreamReader isr = new InputStreamReader(socket.getInputStream());

        int b;
        while ((b = isr.read()) != -1) {
            System.out.print((char)b);
        }
        socket.close();
    }
}
